

public class ReturnStmt extends Statement {

	Expression expression;

	public ReturnStmt(Expression expression) {
		super();
		this.expression = expression;
	}

	public void check() throws SemanticException {
		expression.check();
		// check that the return type is the same as the method
		if (!(expression.checkType() == SymbolTable.getInstance()
				.getCurrentMethod().type))
			throw new SemanticException(
					"Return type must be the same as the method");
	}

	public boolean isReturnStatement() {
		return true;
	}

	public boolean hasReturnStatement() {
		return true;
	}

	public String toString() {
		String ret = "Return\n";
		String s = expression.toString();
		for (String st : s.split("\n"))
			ret += "| " + st + "\n";
		return ret;
	}
}
